<?php
declare (strict_types = 1);

namespace app\admin\controller\school;

use app\common\model\AdminAdmin;
use app\common\model\SchoolCustomerSource;
use think\facade\Request;
use app\common\service\SchoolCustomerWorker as S;
use app\common\model\SchoolCustomerWorker as M;

class CustomerWorker extends  \app\admin\controller\Base
{
    protected $middleware = ['AdminCheck'];

    // 列表
    public function index(){return $this->getAuto($this->fetch(),M::getList());}

    // 添加
    public function add(){return $this->getAuto($this->fetch(),S::goAdd(Request::post()));}

    // 编辑
    public function edit($id){return $this->getAuto($this->fetch('',['model' => AdminAdmin::find($id)]),S::goEdit(Request::post(),$id));}

    // 状态
    public function status($id){return $this->getJson(S::goStatus(Request::post('status'),$id));}

    // 删除
    public function remove($id){return $this->getJson(S::goRemove($id));}

    // 批量删除
    public function batchRemove(){return $this->getJson(S::goBatchRemove(Request::post('ids')));}

    // 回收站
    public function recycle(){return $this->getAuto($this->fetch(),S::goRecycle());}
    //意向客户数
    public function customCount(){
        $class = input('param.class_id');
        $id = session('admin.id');
        $admin = AdminAdmin::where('id', $id)->find();
        $list  = SchoolCustomerSource::field('id,source_info')
            ->where('school_id', $admin['school_id'])
            ->select();
        return $this->getAuto($this->fetch('',['class'=>$class,'list'=>$list]),S::customCount($class));
    }

}
